package com.shanghaiyimu.yimiyangche.mvplogin;

import android.os.Handler;
import android.text.TextUtils;
import android.widget.Toast;

/**
 * Author:ShangHaiYiMu
 * Time:2017/7/13   12:05
 * Description:LoginModelImpl
 *  延时模拟登陆（2s），如果名字或者密码为空则登陆失败，否则登陆成功
 */

public class LoginModelImpl implements ILoginModel {

     public interface OnLoginFinishedListener{

         void onUsernameError();

         void onPasswordError();

         void onSuccess();

     }

    @Override
    public void login(final String username, final String password, final OnLoginFinishedListener finishedListener) {
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                boolean error = false;
                if (TextUtils.isEmpty(username)){
                    finishedListener.onUsernameError();
                    error = true;
                }
                if (TextUtils.isEmpty(password)){
                    finishedListener.onPasswordError();
                    error = true;
                }
                if (!error){
                        finishedListener.onSuccess();
                }
            }
        },2000);
    }
}
